<template>
  <div>
    <div class="form">
      <el-form ref="form" :model="form" label-width="80px">
        <div class="form-top">
          <el-form-item label="标题">
            <el-input
              style="width: 200px"
              v-model="form.title"
              size="small"
            ></el-input>
          </el-form-item>

          <el-form-item label="分类">
            <el-select
              size="small"
              style="width: 112px"
              v-model="form.cid"
              placeholder="请选择类别"
            >
              <el-option
                v-for="(item, index) in classify"
                :key="index"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="用时">
            <el-input-number
              style="width: 100px"
              size="small"
              v-model="form.time"
              label="描述文字"
            ></el-input-number>
          </el-form-item>
        </div>
        <el-form-item label="内容">
          <mavonEditor
            style="max-height: 500px; overflow-y: scroll"
            v-model="form.content"
          ></mavonEditor>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">保存</el-button>
          <el-button @click="cal">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { mavonEditor } from "mavon-editor";
import "mavon-editor/dist/css/index.css";
import { mapState, mapMutations, mapActions } from "vuex";
export default {
  data() {
    return {
      
    };
  },
  methods: {
    ...mapMutations("msbdList", ["SET_DRAWER",'SET_FORM']),
    ...mapActions("msbdList", ["saveMsbdlist","upDateMsbdlist"]),

    //   提交
    async onSubmit() {
        if(this.form.id){
            await this.upDateMsbdlist(this.form)
        }else{
            await this.saveMsbdlist(this.form);
        }
      this.$message({
        message: "恭喜你，处理信息成功",
        type: "success",
      });
      this.SET_DRAWER(this.drawer);
      this.SET_FORM({})
    },
    // 取消关闭抽屉
    cal() {
      this.SET_DRAWER(this.drawer);
      this.SET_FORM({})

    },
  },
  computed: {
    ...mapState("msbdList", ["classify", "drawer",'form']),
  },
  components: {
    mavonEditor,
  },
};
</script>

<style scoped>
.form {
  width: 90%;
  /* margin: 0 auto; */
  padding: 0 20px;
}
.form-top {
  display: flex;
  justify-content: space-between;
}
</style>